package com.kchouse.myadapter;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.kchouse.MainActivity;
import com.kchouse.R;
import com.kchouse.bean.DirItem;
import com.kchouse.bean.OrderEvaItem;
import com.kchouse.common.API;
import com.kchouse.common.MyHttpCycleContext;
import com.kchouse.common.ToastUtils;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;

import cn.finalteam.okhttpfinal.BaseHttpRequestCallback;
import cn.finalteam.okhttpfinal.HttpRequest;
import cn.finalteam.okhttpfinal.RequestParams;

public class SuitAdapter extends RecyclerView.Adapter<SuitAdapter.ViewHolder> {

    private ArrayList<DirItem> datas;
    private Context context;


    public SuitAdapter(Context context, ArrayList<DirItem> datas) {
        this.datas = datas;
        this.context = context;
    }

    //创建新View，被LayoutManager所调用
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int position) {

        View view = null;
        ViewHolder vh = null;
        view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.lv_directly_item, viewGroup, false);
        vh = new ViewHolder(view);
        return vh;
    }

    //将数据与界面进行绑定的操作
    @SuppressLint("ResourceAsColor")
    @Override
    public void onBindViewHolder(ViewHolder viewHolder, final int position) {


        final DirItem item = datas.get(position);
//        viewHolder.tv_merchantName.setText(item.getMerchantShortName());
//        viewHolder.tv_createTime.setText(item.getConsumeTime());
//        viewHolder.tv_projectName.setText(item.getProjectName());
//
//        if (TextUtils.isEmpty(item.getCarNumber())) {
//            viewHolder.tv_carNumber.setVisibility(View.GONE);
//        } else {
//            viewHolder.tv_carNumber.setText("车牌号:"+item.getCarNumber());
//            viewHolder.tv_carNumber.setVisibility(View.VISIBLE);
//        }
//
//        if (item.getStatus().equals("PUSH")) {
//            viewHolder.tv_subeva.setText("未确认");
//            viewHolder.tv_subeva.setOnClickListener(new EvaOnClick(position, viewHolder.tv_subeva));
//            viewHolder.tv_subeva.setClickable(true);
//            viewHolder.tv_subeva.setBackground(context.getResources().getDrawable(R.drawable.bg_corners_blue3_btn));
//            viewHolder.tv_subeva.setTextColor(context.getResources().getColor(R.color.text_main));
//        } else {
//            viewHolder.tv_subeva.setText("已确认");
//            viewHolder.tv_subeva.setTextColor(context.getResources().getColor(R.color.colorblack));
//            viewHolder.tv_subeva.setClickable(false);
//            viewHolder.tv_subeva.setBackground(context.getResources().getDrawable(R.drawable.bg_corners_gray_btn2));
//            viewHolder.tv_subeva.setOnClickListener(null);
//        }



        viewHolder.tv_original.setText(item.getOriginalPrice()+"");
        viewHolder.tv_original.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);//添加下划线

        Picasso.with(context).load(item.getUrl()).error(R.mipmap.ic_loadingerror).into(viewHolder.iv_item);

        viewHolder.tv_price.setText(item.getPrice()+"");

        viewHolder.tv_sales.setText("销量：" + item.getSales());

        viewHolder.tv_title.setText(item.getName());

        if (item.getCouponLimit() == 0) {
            viewHolder.tv_giving.setText("" );
        } else {
            viewHolder.tv_giving.setText("最高抵扣" + (item.getCouponLimit() * 10) + "元");
        }

    }




    //获取数据的数量
    @Override
    public int getItemCount() {
        return datas.size();
    }

    //自定义的ViewHolder，持有每个Item的的所有界面元素
    public class ViewHolder extends RecyclerView.ViewHolder {

        public TextView tv_original;
        public ImageView iv_item;
        public TextView tv_price;
        public TextView tv_sales;
        public TextView tv_title;
        public TextView tv_giving;

        public ViewHolder(View view) {
            super(view);
             tv_original = (TextView) view.findViewById(R.id.tv_original);
             iv_item = (ImageView) view.findViewById(R.id.iv_item);
             tv_price = (TextView) view.findViewById(R.id.tv_price);
             tv_sales = (TextView) view.findViewById(R.id.tv_sales);
             tv_title = (TextView) view.findViewById(R.id.tv_title);
             tv_giving = (TextView) view.findViewById(R.id.tv_giving);
        }
    }


}
